using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using usbLan;
using System.IO;
using System.IO.Ports;
using System.Net.Sockets;
using System.Net;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;

namespace TestDll.controlInterface
{
    public partial class emcBenchtopAmplifierForm : Form
    {
        SerialPort usbPort = null;
        Socket tcpConnect = null;
        string[] e2Strings = { "E1", "E2", "E3", "E4", "E5"};
        public emcBenchtopAmplifierForm()
        {
            InitializeComponent();
            rbUSB.Checked = true;
            gbUSBport.Enabled = true;
            gbLANport.Enabled = false;
            btRefreshCOMx_Click(null, null);
            btRefreshLocalIP_Click(null, null);
        }
        private void comboBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }
        private void btRefreshCOMx_Click(object sender, EventArgs e)
        {
            cbbCOMx.Items.Clear();
            string[] comPorts = commonModule.getCOMnames();
            for (int i = 0; i < comPorts.Length; i++)
            {
                cbbCOMx.Items.Add(comPorts[i]);
            }
            if(comPorts.Length >0)
                cbbCOMx.Text = comPorts[0];
        }
        private void btRefreshLocalIP_Click(object sender, EventArgs e)
        {
            cbbLocalIP.Items.Clear();
            string[] localIPs = commonModule.getLocalIPs();
            for (int i = 0; i < localIPs.Length; i++)
            {
                cbbLocalIP.Items.Add(localIPs[i]);
            }
            if(localIPs.Length >0)
                cbbLocalIP.Text = localIPs[0];
        }
        private void rbUSB_Click(object sender, EventArgs e)
        {
            rbUSB.Checked = true;
            gbUSBport.Enabled = true;
            gbLANport.Enabled = false;
        }
        private void rbLan_Click(object sender, EventArgs e)
        {
            rbLan.Checked = true;
            gbUSBport.Enabled = false;
            gbLANport.Enabled = true;
        }
        private void btConnectDevice_Click(object sender, EventArgs e)
        {
            if (rbUSB.Checked)
            {
                if (btConnect.Text == "Connect Device")
                {
                    usbPort = usbLan.commonModule.openConnectUSB(cbbCOMx.Text, Convert.ToInt32(cbbBaud.Text));
                    tbDeviceInfos.Text = usbLan.commonModule.getProductInformationUSB(usbPort); 
                    btConnect.Text = "Close Connect";
                    btConnect.ForeColor = Color.Red;
                    btConnect.BackColor = Color.LimeGreen;
                }
                else
                {
                    usbLan.commonModule.closeConnectUSB(usbPort);
                    btConnect.Text = "Connect Device";
                    btConnect.ForeColor = Color.Blue;
                    btConnect.BackColor = Color.Transparent;
                    tbDeviceInfos.Text = "";
                }
            }
            else
            {
                if (btConnect.Text == "Connect Device")
                {
                    try
                    {
                        tcpConnect = usbLan.commonModule.openConnectTCP(cbbLocalIP.Text, tbDeviceIP.Text, Convert.ToInt32(nudDevicePort.Value));
                        tbDeviceInfos.Text = usbLan.commonModule.getProductInformationTCP(tcpConnect);
                        btConnect.Text = "Close Connect";
                        btConnect.ForeColor = Color.Red;
                        btConnect.BackColor = Color.LimeGreen;
                    }
                    catch
                    {
                        tbDeviceInfos.Text = "";
                        usbLan.commonModule.closeConnectTCP(tcpConnect);
                        MessageBox.Show("Connect failure!");
                    }
                }
                else
                {
                    try
                    {
                        usbLan.commonModule.closeConnectTCP(tcpConnect);
                        btConnect.Text = "Connect Device";
                        btConnect.ForeColor = Color.Blue;
                        btConnect.BackColor = Color.Transparent;
                        tbDeviceInfos.Text = "";
                    }
                    catch
                    {
                        MessageBox.Show("Close failure!");
                    }
                }
                
            }
            //tbRecStr.Text = usbLan.emcBenchtopAmplifier.getOutputStatusUSB(usbPort) ? "Open" : "Closed";
        }
        private void btReset_Click(object sender, EventArgs e)
        {
            if(rbUSB.Checked)
            {
                usbLan.commonModule.resetDeviceUSB(usbPort); //Restart the device
            }
            else
            {
                usbLan.commonModule.resetDeviceTCP(tcpConnect);
            }
        }
        private void btSeBaudrate_Click(object sender, EventArgs e)
        {
            tbRecStr.Text = null;
            if(rbUSB.Checked)
            {
                tbRecStr.Text = usbLan.commonModule.setBaudrateUSB(usbPort, cbbNewBaudrate.SelectedIndex);
                //queryError(tbRecStr.Text);
            }
            else
            {
                MessageBox.Show("This function only for USB port!");
            }
        }

        private void btExecute_Click(object sender, EventArgs e)
        {
            tbRecStr.Text = null;
            tbRecStr.Refresh();
            System.Threading.Thread.Sleep(200);
            if (rbUSB.Checked)
            {
                switch (cbbType.SelectedIndex)
                {
                    
                    case 0:
                        tbRecStr.Text = usbLan.commonModule.getProductInformationUSB(usbPort);
                        break;
                    case 1:
                        tbRecStr.Text = usbLan.commonModule.getMAC_USB(usbPort);
                        break;
                    case 2:
                        tbRecStr.Text = usbLan.emcBenchtopAmplifier.setOutputStatusUSB(usbPort, cbStatus.Checked);
                        break;
                    case 3:
                        tbRecStr.Text = usbLan.emcBenchtopAmplifier.setFrequencyUSB(usbPort, nudValue.Value);
                        break;
                    case 4:
                        tbRecStr.Text = usbLan.emcBenchtopAmplifier.setAttenuationUSB(usbPort, nudValue.Value);
                        break;
                    case 5:
                        tbRecStr.Text = usbLan.emcBenchtopAmplifier.setOutputPowerUSB(usbPort, nudValue.Value);
                        break;
                    case 6:
                        tbRecStr.Text = usbLan.emcBenchtopAmplifier.setAlcStatusUSB(usbPort, cbStatus.Checked);
                        
                        break;
                    case 7:
                        bool open = usbLan.emcBenchtopAmplifier.getOutputStatusUSB(usbPort);
                        if (!usbLan.emcBenchtopAmplifier.getErrorOccur())
                            tbRecStr.Text = open ? "Open" : "Closed";
                        else
                            tbRecStr.Text = usbLan.emcBenchtopAmplifier.getErrorCode();
                        break;
                    case 8:
                        {
                            decimal value = usbLan.emcBenchtopAmplifier.getFrequencyUSB(usbPort);
                            if (!usbLan.emcBenchtopAmplifier.getErrorOccur())
                                tbRecStr.Text = value.ToString();
                            else
                                tbRecStr.Text = usbLan.emcBenchtopAmplifier.getErrorCode();
                            //tbRecStr.Text = usbLan.emcBenchtopAmplifier.getFrequencyUSB(usbPort).ToString();
                        }
                            break;
                    case 9:
                        {
                            decimal value = usbLan.emcBenchtopAmplifier.getAttenuationUSB(usbPort);
                            if (!usbLan.emcBenchtopAmplifier.getErrorOccur())
                                tbRecStr.Text = value.ToString();
                            else
                                tbRecStr.Text = usbLan.emcBenchtopAmplifier.getErrorCode();
                            //tbRecStr.Text = usbLan.emcBenchtopAmplifier.getAttenuationUSB(usbPort).ToString();

                        }
                        break;
                    case 10:
                        {
                                tbRecStr.Text = usbLan.emcBenchtopAmplifier.getInputPowerUSB(usbPort).ToString();
                           
                            //tbRecStr.Text = usbLan.emcBenchtopAmplifier.getInputPowerUSB(usbPort).ToString();

                        }
                        break;
                    case 11:
                        {
                            decimal value = usbLan.emcBenchtopAmplifier.getOutputPowerUSB(usbPort);
                            if (!usbLan.emcBenchtopAmplifier.getErrorOccur())
                                tbRecStr.Text = value.ToString();
                            else
                                tbRecStr.Text = usbLan.emcBenchtopAmplifier.getErrorCode();
                            //tbRecStr.Text = usbLan.emcBenchtopAmplifier.getOutputPowerUSB(usbPort).ToString();
                        }
                        break;
                    case 12:
                        {
                            decimal alcValue = 0;
                            bool alcStatus = usbLan.emcBenchtopAmplifier.getAlcStatusUSB(usbPort, out alcValue);
                            if (!usbLan.emcBenchtopAmplifier.getErrorOccur())
                            {
                                tbRecStr.Text = (alcStatus ? "Open" : "Closed") + "," + Math.Round(alcValue, 1).ToString();
                            }
                            else
                                tbRecStr.Text = usbLan.emcBenchtopAmplifier.getErrorCode();
                            /*decimal alcValue = 0;
                            bool alcStatus = usbLan.emcBenchtopAmplifier.getAlcStatusUSB(usbPort,out alcValue);
                            tbRecStr.Text = ((alcStatus ? "Open" : "Closed") + "," + Math.Round(alcValue, 1));*/
                        }
                        break;
                    case 13:
                            tbRecStr.Text = usbLan.emcBenchtopAmplifier.getOutputVswrUSB(usbPort).ToString();
                        //tbRecStr.Text = usbLan.emcBenchtopAmplifier.getOutputVswrUSB(usbPort).ToString();
                        break;
                    case 14:
                        {
                            decimal value = usbLan.emcBenchtopAmplifier.getTemperatureUSB(usbPort);
                            if (!usbLan.emcBenchtopAmplifier.getErrorOccur())
                                tbRecStr.Text = value.ToString();
                            else
                                tbRecStr.Text = usbLan.emcBenchtopAmplifier.getErrorCode();
                            //tbRecStr.Text = usbLan.emcBenchtopAmplifier.getTemperatureUSB(usbPort).ToString();
                        }
                        break;
                    case 15:
                        decimal[] freqRange = usbLan.emcBenchtopAmplifier.getFrequencyRangeUSB(usbPort);
                        if (!usbLan.emcBenchtopAmplifier.getErrorOccur()) {
                            //decimal[] freqRange = usbLan.emcBenchtopAmplifier.getFrequencyRangeUSB(usbPort);
                            tbRecStr.Text = freqRange[0] + "-" + freqRange[1];
                        }
                        else
                            tbRecStr.Text = usbLan.emcBenchtopAmplifier.getErrorCode();
                        /*decimal[] freqRange = usbLan.emcBenchtopAmplifier.getFrequencyRangeUSB(usbPort);
                        tbRecStr.Text = freqRange[0] + "-" + freqRange[1];*/
                        break;
                    case 16:
                        decimal[] attRange = usbLan.emcBenchtopAmplifier.getAttenuationRangeUSB(usbPort);
                        if (!usbLan.emcBenchtopAmplifier.getErrorOccur()) {
                           
                            tbRecStr.Text = attRange[0] + "-" + attRange[1];
                        }
                        else
                            tbRecStr.Text = usbLan.emcBenchtopAmplifier.getErrorCode();
                        
                        break;
                    case 17:
                        string recstr = usbLan.emcBenchtopAmplifier.getAlarmUSB(usbPort);
                        tbRecStr.Text =recstr;
                        break;
                    /*case 18:
                        tbRecStr.Text = usbLan.emcBenchtopAmplifier.SetPowerSupplyUSB(usbPort, true);
                        break;
                    case 19:
                        tbRecStr.Text = usbLan.emcBenchtopAmplifier.SetPowerSupplyUSB(usbPort, false);
                        break;
                    case 20:
                        bool state = false;
                        state = usbLan.emcBenchtopAmplifier.GetPowerSupplyUSB(usbPort);
                        if(state == false)
                        {
                            tbRecStr.Text = "0";
                        }
                        else
                        {
                            tbRecStr.Text = "1";
                        }
                        break;*/
                    case 18:
                        {
                            
                            tbRecStr.Text = usbLan.emcBenchtopAmplifier.SetAGCUSB(usbPort, cbStatus.Checked, nudValue.Value);
                            Console.WriteLine(tbRecStr.Text);
                        }
                        break;
                    case 19:
                        {
                            decimal agcvalue = 0;
                            decimal Cugain = 0;
                            bool agcstatus = usbLan.emcBenchtopAmplifier.GetAGCUSB(usbPort, out agcvalue, out Cugain);
                            if (!usbLan.emcBenchtopAmplifier.getErrorOccur())
                                {

                                tbRecStr.Text = agcstatus ? "1" : "0" + "," + agcvalue.ToString("F1") + "," + Cugain.ToString("F1");
                            }
                            else
                                tbRecStr.Text = usbLan.emcBenchtopAmplifier.getErrorCode();   
                        }
                        break;
                    case 20:
                        {
                            string result = usbLan.emcBenchtopAmplifier.SetSweepUSB(usbPort, decimal.Parse(txt_sweepStartFreq.Text), decimal.Parse(txt_sweepStepFreq.Text), decimal.Parse(txt_sweepStopFreq.Text), decimal.Parse(txt_sweepDelay.Text), decimal.Parse(txt_sweepLevel.Text));
                            tbRecStr.Text = result;
                        }
                        break;
                    case 21:
                        {
                            string result = usbLan.emcBenchtopAmplifier.GetSweepUSB(usbPort);
                            tbRecStr.Text = result;
                        }
                        break;
                    case 22:
                        {
                            string result = usbLan.emcBenchtopAmplifier.SetSweepStatusUSB(usbPort, cbStatus.Checked);
                            tbRecStr.Text = result;
                        }
                        break;
                    case 23:
                        {
                            string result = usbLan.emcBenchtopAmplifier.GetSweepStatusUSB(usbPort);
                            tbRecStr.Text = result;
                        }
                        break;
                    case 24:
                        {
                            string result = usbLan.emcBenchtopAmplifier.SetHopUSB(usbPort, decimal.Parse(txt_hopnum.Text), decimal.Parse(txt_hopfreq.Text), decimal.Parse(txt_hoplevel.Text), decimal.Parse(txt_hopdelay.Text));
                            tbRecStr.Text = result;
                        }
                        break;
                    case 25:
                        {
                            string result = usbLan.emcBenchtopAmplifier.GetHopUSB(usbPort, decimal.Parse(nudValue.Text.Split('.')[0]));
                            tbRecStr.Text = result;
                        }
                        break;
                    case 26:
                        {
                            string result = usbLan.emcBenchtopAmplifier.SetHopStatus(usbPort, cbStatus.Checked);
                            tbRecStr.Text = result;
                        }
                        break;
                    case 27:
                        {
                            string result = usbLan.emcBenchtopAmplifier.GetHopStatus(usbPort);
                            tbRecStr.Text = result;
                        }
                        break;
                    case 28:
                        {
                            string result = usbLan.emcBenchtopAmplifier.GetLevelRange(usbPort);
                            tbRecStr.Text = result;
                        }
                        break;
                    case 29:
                        {
                            string result = usbLan.emcBenchtopAmplifier.SetSigLevelUSB(usbPort, nudValue.Value);
                            tbRecStr.Text = result;
                        }
                        break;
                    case 30:
                        {
                            string result = usbLan.emcBenchtopAmplifier.SetSigModeUSB(usbPort, cbStatus.Checked);
                            tbRecStr.Text = result;
                        }
                        break;
                    case 31:
                        {
                            string result = usbLan.emcBenchtopAmplifier.GetSigModeUSB(usbPort);
                            tbRecStr.Text = result;
                        }
                        break;
                    default:
                        Console.WriteLine(cbbType.SelectedIndex);
                        break;
                }
            }
            else
            {
                switch (cbbType.SelectedIndex)
                {
                    case 0:
                        tbRecStr.Text = usbLan.commonModule.getProductInformationTCP(tcpConnect);
                        break;
                    case 1:
                        tbRecStr.Text = usbLan.commonModule.getMAC_TCP(tcpConnect);
                        break;
                    case 2:
                        tbRecStr.Text = usbLan.emcBenchtopAmplifier.setOutputStatusTCP(tcpConnect, cbStatus.Checked);
                        break;
                    case 3:
                        tbRecStr.Text = usbLan.emcBenchtopAmplifier.setFrequencyTCP(tcpConnect, nudValue.Value);
                        break;
                    case 4:
                        tbRecStr.Text = usbLan.emcBenchtopAmplifier.setAttenuationTCP(tcpConnect, nudValue.Value);
                        break;
                    case 5:
                        tbRecStr.Text = usbLan.emcBenchtopAmplifier.setOutputPowerTCP(tcpConnect, nudValue.Value);
                        break;
                    case 6:
                        tbRecStr.Text = usbLan.emcBenchtopAmplifier.setAlcStatusTCP(tcpConnect, cbStatus.Checked);
                        break;
                    case 7:
                        bool open = usbLan.emcBenchtopAmplifier.getOutputStatusTCP(tcpConnect);
                        if (!usbLan.emcBenchtopAmplifier.getErrorOccur())
                            tbRecStr.Text = open ? "Open" : "Closed";
                        else
                            tbRecStr.Text = usbLan.emcBenchtopAmplifier.getErrorCode();
                        break;
                    case 8:
                        {
                            decimal value = usbLan.emcBenchtopAmplifier.getFrequencyTCP(tcpConnect);
                            if (!usbLan.emcBenchtopAmplifier.getErrorOccur())
                                tbRecStr.Text = value.ToString();
                            else
                                tbRecStr.Text = usbLan.emcBenchtopAmplifier.getErrorCode();
                        }
                        //tbRecStr.Text = usbLan.emcBenchtopAmplifier.getFrequencyTCP(tcpConnect).ToString();
                        break;
                    case 9:
                        {
                            decimal value = usbLan.emcBenchtopAmplifier.getAttenuationTCP(tcpConnect);
                            if (!usbLan.emcBenchtopAmplifier.getErrorOccur())
                                tbRecStr.Text = value.ToString();
                            else
                                tbRecStr.Text = usbLan.emcBenchtopAmplifier.getErrorCode();
                            //tbRecStr.Text = usbLan.emcBenchtopAmplifier.getAttenuationUSB(usbPort).ToString();

                        }
                    
                        break;
                    case 10:
                        tbRecStr.Text = usbLan.emcBenchtopAmplifier.getInputPowerTCP(tcpConnect).ToString();
                        break;
                    case 11:
                        {
                            decimal value = usbLan.emcBenchtopAmplifier.getOutputPowerTCP(tcpConnect);
                            if (!usbLan.emcBenchtopAmplifier.getErrorOccur())
                                tbRecStr.Text = value.ToString();
                            else
                                tbRecStr.Text = usbLan.emcBenchtopAmplifier.getErrorCode();
                            //tbRecStr.Text = usbLan.emcBenchtopAmplifier.getOutputPowerUSB(usbPort).ToString();
                        }
                        break;
                    case 12:
                        decimal alcValue = 0;
                        bool alcStatus = usbLan.emcBenchtopAmplifier.getAlcStatusTCP(tcpConnect,out alcValue);
                        if (!usbLan.emcBenchtopAmplifier.getErrorOccur())
                        {
                            tbRecStr.Text = (alcStatus ? "Open" : "Closed") + "," + Math.Round(alcValue, 1).ToString();
                        }
                        else
                            tbRecStr.Text = usbLan.emcBenchtopAmplifier.getErrorCode();
                        
                        break;
                    case 13:
                        tbRecStr.Text = usbLan.emcBenchtopAmplifier.getOutputVswrTCP(tcpConnect).ToString();
                        break;
                    case 14:
                        {
                            decimal value = usbLan.emcBenchtopAmplifier.getTemperatureTCP(tcpConnect);
                            if (!usbLan.emcBenchtopAmplifier.getErrorOccur())
                                tbRecStr.Text = value.ToString();
                            else
                                tbRecStr.Text = usbLan.emcBenchtopAmplifier.getErrorCode();
                            //tbRecStr.Text = usbLan.emcBenchtopAmplifier.getTemperatureTCP(tcpConnect).ToString();
                        }
                        break;
                    case 15:
                        decimal[] freqRange = usbLan.emcBenchtopAmplifier.getFrequencyRangeTCP(tcpConnect);
                        if (!usbLan.emcBenchtopAmplifier.getErrorOccur())
                        {
                            //decimal[] freqRange = usbLan.emcBenchtopAmplifier.getFrequencyRangeUSB(usbPort);
                            tbRecStr.Text = freqRange[0] + "-" + freqRange[1];
                        }
                        else
                            tbRecStr.Text = usbLan.emcBenchtopAmplifier.getErrorCode();
                        /*decimal[] freqRange = usbLan.emcBenchtopAmplifier.getFrequencyRangeTCP(tcpConnect);
                        tbRecStr.Text = freqRange[0] + "-" + freqRange[1];*/
                        break;
                    case 16:
                        decimal[] attRange = usbLan.emcBenchtopAmplifier.getAttenuationRangeTCP(tcpConnect);
                        if (!usbLan.emcBenchtopAmplifier.getErrorOccur())
                        {

                            tbRecStr.Text = attRange[0] + "-" + attRange[1];
                        }
                        else
                            tbRecStr.Text = usbLan.emcBenchtopAmplifier.getErrorCode();
                        /*decimal[] attRange = usbLan.emcBenchtopAmplifier.getAttenuationRangeTCP(tcpConnect);
                        tbRecStr.Text = attRange[0] + "-" + attRange[1];*/
                        break;
                    case 17:
                        string alarms = usbLan.emcBenchtopAmplifier.getAlarmTCP(tcpConnect);
                        tbRecStr.Text = alarms;
                        break;
                    /*case 18:
                        tbRecStr.Text = usbLan.emcBenchtopAmplifier.SetPowerSupplyTCP(tcpConnect, true);
                        break;
                    case 19:
                        tbRecStr.Text = usbLan.emcBenchtopAmplifier.SetPowerSupplyTCP(tcpConnect, false);
                        break;
                    case 20:
                        bool state = false;
                        state = usbLan.emcBenchtopAmplifier.GetPowerSupplyTCP(tcpConnect);
                        if (state == true)
                        {
                            tbRecStr.Text = "1";
                        }
                        else
                        {
                            tbRecStr.Text = "0";
                        }                       
                        break;*/
                    case 18:
                        {
                            tbRecStr.Text = usbLan.emcBenchtopAmplifier.SetAGCTCP(tcpConnect, cbStatus.Checked, nudValue.Value);
                            //Console.WriteLine(usbLan.emcBenchtopAmplifier.SetAGCTCP(tcpConnect, cbStatus.Checked, nudValue.Value));
                        }
                        break;
                    case 19:
                        {
                            decimal agcvalue = 0;
                            decimal cugain = 0;
                            bool agcstatus = usbLan.emcBenchtopAmplifier.GetAGCTCP(tcpConnect, out agcvalue, out cugain);
                            if (!usbLan.emcBenchtopAmplifier.getErrorOccur())
                            {

                                tbRecStr.Text = agcstatus ? "1" : "0" + "," + agcvalue.ToString("F1") + "," + cugain.ToString("F1");
                            }
                            else
                                tbRecStr.Text = usbLan.emcBenchtopAmplifier.getErrorCode();
                        }

                        break;
                    default:
                        break;
                }
            }
            if(e2Strings.Contains(tbRecStr.Text))
            {
                queryError(tbRecStr.Text);
            }    
        }
        private void queryError(string e2Code)
        {
            if(e2Code == null)
            {
                MessageBox.Show("Excute error!");
            }
            else
            {
                string hints = usbLan.commonModule.queryErrorDescription(e2Code);
                if(hints != null)
                {
                    MessageBox.Show(hints);
                }
            }

        }
        public static string sendOrderUSB(SerialPort usbPort, string sendStr)
        {
            usbPort.Write(sendStr);
            System.Threading.Thread.Sleep(150);
            usbPort.ReadTimeout = 500;
            Byte[] recData = new Byte[512];
            usbPort.Read(recData, 0, recData.Length);
            string reStr = Encoding.UTF8.GetString(recData).TrimEnd('\n');
            return reStr;
        }

        public void ENABLE_TXT(bool status)
        {
            if(status == true)
            {
                txt_hopdelay.Enabled = true;
                txt_hopfreq.Enabled = true;
                txt_hoplevel.Enabled = true;
                txt_hopnum.Enabled = true;
                txt_sweepDelay.Enabled = true;
                txt_sweepLevel.Enabled = true;
                txt_sweepStartFreq.Enabled = true;
                txt_sweepStepFreq.Enabled = true;
                txt_sweepStopFreq.Enabled = true;
            }
            else
            {
                txt_hopdelay.Enabled = false;
                txt_hopfreq.Enabled = false;
                txt_hoplevel.Enabled = false;
                txt_hopnum.Enabled = false;
                txt_sweepDelay.Enabled = false;
                txt_sweepLevel.Enabled = false;
                txt_sweepStartFreq.Enabled = false;
                txt_sweepStepFreq.Enabled = false;
                txt_sweepStopFreq.Enabled = false;
            }
        }

        private void rbUSB_CheckedChanged(object sender, EventArgs e)
        {
            ENABLE_TXT(true);
        }

        private void rbLan_CheckedChanged(object sender, EventArgs e)
        {
            ENABLE_TXT(false);
        }
    }
}
